<?php

chdir('../../');
require ('includes/application_top.php');
require_once(DIR_FS_CATALOG.'callback/sofort/helperFunctions.php');

$language = $_SESSION['language'];

if (is_file('lang/'.$language.'/modules/payment/sofort_general.php')) {
	include('lang/'.$language.'/modules/payment/sofort_general.php');
}else{
	include('lang/english/modules/payment/sofort_general.php');
}

if (ENABLE_SSL == true) {
	$errorUrl = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?'.session_name().'='.session_id().'&payment_error='.$_SESSION['sofort_payment_method'].'&';
}else{
	$errorUrl = HTTPS_SERVER.DIR_WS_CATALOG.FILENAME_CHECKOUT_PAYMENT.'?'.session_name().'='.session_id().'&payment_error='.$_SESSION['sofort_payment_method'].'&';
}

//something is wrong, redirect to payment-page
if(!$_SESSION['payment'] || !$_SESSION['sofort_payment_url']){
	$sofortPaymentUrl = $errorUrl;
}else{
	$sofortHost = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://www.sofort.com';
	$hostToCheck = parse_url($sofortHost, PHP_URL_HOST);
	$paymentHost = parse_url($_SESSION['sofort_payment_url'], PHP_URL_HOST);
	if (strpos($paymentHost, $hostToCheck) === false) {
		//host is not a sofort-host
		$sofortPaymentUrl = $errorUrl;
	}else{
		//redirect to pnag
		$sofortPaymentUrl = $_SESSION['sofort_payment_url'];
	}
	unset($_SESSION['sofort_payment_url']);
	unset($_SESSION['sofort_payment_method']);
}

echo '
	<head>
		<meta http-equiv="refresh" content="0; URL='.$sofortPaymentUrl.'/">
		<meta content="text/html; charset='.HelperFunctions::getIniValue('shopEncoding').'" http-equiv="Content-Type">
	</head>
	<body>
		<div style="text-align:center;">
			<div style="height:50px;">&nbsp;</div>
			<div style="height:50px;">
				<img src="../../callback/sofort/loader.gif" alt="" />
			</div>
			<div style="height:50px;">
				'.MODULE_PAYMENT_SOFORT_MULTIPAY_FORWARDING.'
			</div>
			<div>
				<img src="https://images.sofort.com/de/pnag/logo.gif" alt="" />
			</div>
		</div>
	</body>';
?>